package com.sw.study.presisence.sqlsession;

import com.sw.study.presisence.config.XMLConfigBuider;
import com.sw.study.presisence.pojo.Configuration;
import com.sw.study.presisence.sqlsession.sessionfactory.SqlSessionFactory;
import com.sw.study.presisence.sqlsession.sessionfactory.impl.DefaultSqlSessionFactory;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * Created by sw on 2020/3/25.
 * 构建数据库连接
 *
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory buid(InputStream inputStream) throws DocumentException, PropertyVetoException {
        /**
         * dom4j 解析配置文件 完成数据db 和sql的封装
         */
        XMLConfigBuider xmlConfigBuider=new XMLConfigBuider();
        Configuration configuration=xmlConfigBuider.parseConfig(inputStream);
        /**
         * 创建sessionFactory   工厂类  作用，产生session：数据库连接会话对象
         */
        SqlSessionFactory sqlSessionFactory=new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }

}